/**
 * Boolean
 */
let isDone: boolean = false;

/**
 * Number
 */
let decLiteral:number = 6; //十进制
let hexLiteral:number = 0xf00d; //十六进制
let binaryLiteral:number = 0b1010; //二进制
let octalLiteral:number = 0o744; //八进制
let bigLiteral:bigint=100n 

/**
 * String
 */
let nameTo1:string = "bob";
nameTo1 = "smith";
//模板字符串
let nameTo2:string = `Gene`;
let age:number = 37;
let sentence:string = `Hello, my name is ${nameTo2} , I'll be ${age + 1} years old next month`;

/**
 * Array
 */
let list :number [] = [1,2,3,4];
// 使用数组泛型,Attay<元素类型>
let listTo1:Array<number> = [1,2,3,4]

/**
 * Tuple
 * 元组中元素与类型一一对应
 */
let x : [string,number]; //声明元组
x = ["Hello",23]; //初始化元组

/**
 * Enum 枚举
 */
enum Color {Red,Green,Blue};
let c :Color = Color.Green;
enum ColorTo1 {Red=1,Green=2,Blue=4} //手动添加编号
let colorName:string =ColorTo1[4]  //Blue
console.log(colorName);

/**
 * Unknown
 */
let notSure:unknown = 4;
notSure = "maybe a string instead";
notSure = true;
// @errors: 2322 2322 2322
declare const maybe: unknown;
// 'maybe' could be a string, object, boolean, undefined, or other types
// const aNumber: number = maybe; ==>不能将类型“unknown”分配给类型“number”
if (maybe === true) {
  // TypeScript knows that maybe is a boolean now
  const aBoolean: boolean = maybe;
  // So, it cannot be a string
  // const aString: string = maybe; ==>不能将类型“boolean”分配给类型“string”
}

if (typeof maybe === "string") {
  // TypeScript knows that maybe is a string
  const aString: string = maybe;
  // So, it cannot be a boolean
  // const aBoolean: boolean = maybe; ==>不能将类型“string”分配给类型“boolean”
}

/**
 * Any
 */
let notSureTo1:any = 4;
notSureTo1 = "maybe a string instead";
notSureTo1 = false ;
notSureTo1.ifItExists();
notSureTo1.toFixed();
let listTo2:any[] = [1,true,"free"];
listTo2[2] = 20;

/**
 * Void
 */
function warnUser():void {
  console.log("this is my warning message");
}

/**
 * Null / Undefined
 */
let u:undefined = undefined;
let n:null = null;

/**
 * Never
 */
function error(message:string):never {  //返回never的函数必须存在无法达到的终点
  throw new Error(message);
}
function fail():never {   //推断的返回值类型为never
  return error("Something failed");
}
function infiniteLoop():never {  //返回never的函数必须存在无法达到的终点
  while(true){}
}

/**
 * Object
 */
declare function create (o:object|null):void
create({prop:0})
create(null)
// create(42) 报错
// create("string") 报错
// create(false) 报错
// create(undefined) 报错

/**
 * 类型断言
 */
let someValue:any = "this is a string";
let strLength:number = (<string>someValue).length;   //尖括号法断言
let strLengthTo1:number = (someValue as string).length  //"as"法断言 
// 在TypeScript里使用JSX时，只有as语法断言是被允许的。